package cn;

import java.util.Arrays;

public class Test {
    public static void transform(int[] array)
    {
        for(int i=0;i<array.length;i++)
        {
            array[i]=array[i]*2;
        }
    }
    public static void odd_before(int[] array){
        int[] odd_array=new int[array.length];
        int[] even_array=new int[array.length];
        int k=0;
        int m=0;
        for(int i=0;i<array.length;i++) {
            if(array[i]%2!=0) {
                odd_array[k]=array[i];
                k++;
            }
            else {
                even_array[m]=array[i];
                m++;
            }
        }
        for(int i=0;i<k;i++) {
            array[i]=odd_array[i];
        }
        for(int i=0;i<m;i++) {
            array[k]=even_array[i];
            k++;
        }
    }
    public static int binary_search(int[] array,int key){
        int left=0;
        int right=array.length-1;
        int mid=0;
        for(int i=0;i<array.length;i++){
            mid=(left+right)/2;
            if(array[mid]>key)
            {
                right=mid-1;
            }
            else if(array[mid]<key)
            {
                left=mid+1;
            }
            else{
                break;
            }
        }
        return mid;
    }
    public static void bubble_sort(int[] array){
        for(int i=0;i<array.length;i++)
        {
            boolean flg=false;
            for(int j=0;j<array.length-1-i;j++){
                if(array[j]>array[j+1])
                {
                    int tmp=array[j];
                    array[j]=array[j+1];
                    array[j+1]=tmp;
                    flg=true;
                }
            }
            if(flg==false){
                return;
            }
        }
    }
    public static int find_one(int[] array){
        int i=0;
        for(i=0;i<array.length;i++)
        {
            boolean flg=false;
            int ret=array[i];
            for(int j=0;j<array.length;j++){
                if(j!=i){
                    if(array[j]==ret){
                        flg=true;
                        break;
                    }
                }
            }
            if(flg==false)
            {
                break;
            }
        }
        return i;
    }
    public static int find_more(int[] array){
        for(int i=0;i<array.length;i++){
            int count=0;
            for(int j=0;j<array.length;j++){
                if(array[i]==array[j]){
                    count++;
                }
            }
            if(count>array.length/2){
                return array[i];
            }
        }
        return -1;
    }

    public static boolean is_odd(int[] arr){
        for(int i=0;i<arr.length-2;i++){
            if(arr[i]%2!=0){
                if(arr[i+1]%2!=0){
                    if(arr[i+2]%2!=0){
                        return true;
                    }
                }
            }
        }
        return false;
    }
        public static int findTargetSumWays(int[] nums, int target) {
            int n=nums.length;
            int sum=0;
            for(int a:nums)
            {
                sum=sum+a;
            }
            int diff=sum-target;
            if(diff<0||diff%2!=0)
            {
                return 0;
            }
            int neg=sum-target/2;
            int[] dp=new int[neg+1];
            dp[0]=1;
            for(int i=1;i<=n;i++)
            {
                int num=nums[i-1];
                for(int j=neg;j>=num;j--)
                {
                    dp[j]+=dp[j-num];
                }
            }
            return dp[neg];
        }

    public static void main6(String[] args) {
        int[] nums=new int[]{1000};
        int a=findTargetSumWays(nums,1000);
        System.out.println(a);
    }
    public static void main5(String[] args) {
        int[] arr=new int[]{2,6,4,1};
        boolean a=is_odd(arr);
        System.out.println(a);
    }

    public static void main4(String[] args) {
        int[] array=new int[]{2,2,1,1,1,2,2};
        int num=find_more(array);
        System.out.println(num);
    }

    public static void main3(String[] args) {
        int[] array=new int[]{2,7,11,15};

    }
    public static void main2(String[] args) {
        int[] array=new int[]{1,5,8,74,41,6};
       bubble_sort(array);
        System.out.println(Arrays.toString(array));
    }
    public static void main1(String[] args) {
        int[] array=new int[]{1,2,3};
        transform(array);
        System.out.println(Arrays.toString(array));
    }




}
